<template>
	<view>
		<view class="flex1">
			<view class="" style="display: flex;align-items: center;">
				剩余取餐时间：<!-- {{time}} -->
				<uni-countdown :show-day="false" :day="1" :hour="hours" :minute="minutes"
					:second="seconds"></uni-countdown>
			</view>
			<image @click="opents" src="/static/ts.png" mode=""></image>
		</view>
		<clearts ref="popupts"></clearts>
	</view>
</template>

<script>
	export default {
		name: "countdown",
		props: {
			time: {
				default: '00:00:00'
			}
		},
		data() {
			return {
				hours: 0,
				minutes: 0,
				seconds: 0,
			};
		},
		computed: {
			times() {
				return this.time
			}
		},
		created() {
			var timeString = this.times // 时分秒字符串
			var currentDate = new Date(); // 当前日期对象
			var dateString = currentDate.toDateString(); // 获取当前日期的字符串表示（不包含时分秒）
			var dateTimeString = dateString + ' ' + timeString; // 拼接日期和时分秒字符串
			var timestamp = Date.parse(dateTimeString); // 将日期时间字符串转换为时间戳
			var nowtimestamp = Date.parse(new Date());
			console.log(timestamp - nowtimestamp); // 输出时间戳
			let now = timestamp - nowtimestamp
			this.hours = Math.floor(now / 3600000);
			this.minutes = Math.floor((now % 3600000) / 60000);
			this.seconds = Math.floor((now % 60000) / 1000);
		},
		methods: {
			opents() {
				this.$refs.popupts.open()
			},
		}
	}
</script>

<style lang="scss">
	.flex1 {
		display: flex;
		align-items: center;
		height: 68rpx;
		background: #F3F3F3;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 26rpx;
		color: #000000;
		justify-content: space-between;
		padding: 0rpx 20rpx;
		box-sizing: border-box;
		width: 710rpx;
		margin: 0 auto;

		image {
			width: 32rpx;
			height: 33rpx;
		}
	}
</style>